<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title></title>
    <%@include file="/WEB-INF/pages/common/basic-styles.jspf" %>
</head>
<body>
	<div class="page-header">
		<h1>
			${op}
		</h1>
	</div><!-- /.page-header -->
    <form:form method="post" commandName="resource" cssClass="form-horizontal" onsubmit="return validForm()">
        <form:hidden path="id"/>
        <form:hidden path="available"/>
        <form:hidden path="parentId"/>
        <form:hidden path="parentIds"/>
        
		<c:if test="${not empty parent}">
			<input type="hidden" id="parentOrderNum" value="${parent.orderNum}">
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="parentName"> 父节点名称 </label>
				<div class="col-sm-9">
					<input type="text" id="parentName" class="col-xs-10 col-sm-5" readonly="readonly" value="${parent.name}"/>
				</div>
			</div>
			<div class="space-4"></div>
		</c:if>
		
		<div class="form-group">
			<form:label path="name" class="col-sm-3 control-label no-padding-right"><c:if test="${not empty parent}">子</c:if>名称：</form:label>
			<div class="col-sm-9">
            	<form:input path="name" class="col-xs-10 col-sm-5"/>
				<span class="help-inline col-xs-12 col-sm-7">
					<span class="middle"><font color="red">*</font></span>
				</span>
			</div>
		</div>
		<div class="space-4"></div>

		<div class="form-group">
			<form:label path="type" class="col-sm-3 control-label no-padding-right"> 类型 </form:label>
			<div class="col-sm-9">
				<form:select path="type" items="${types}" itemLabel="info" class="col-xs-10 col-sm-5"/>
			</div>
		</div>
		<div class="space-4"></div>

		<div class="form-group">
			<form:label path="url" class="col-sm-3 control-label no-padding-right"> URL路径 </form:label>
			<div class="col-sm-9">
				<form:input path="url" class="col-xs-10 col-sm-5"/>
			</div>
		</div>
		<div class="space-4"></div>
		
		<div class="form-group">
			<form:label path="permission" class="col-sm-3 control-label no-padding-right"> 权限字符串 </form:label>
			<div class="col-sm-9">
				<form:input path="permission" class="col-xs-10 col-sm-5"/>
			</div>
		</div>
		<div class="space-4"></div>
		
        <div class="form-group">
			<form:label path="orderNum" class="col-sm-3 control-label no-padding-right"> 排序号 </form:label>
			<div class="col-sm-9">
				<form:input path="orderNum" class="col-xs-10 col-sm-5" maxlength="5"/>
				<span class="help-inline col-xs-12 col-sm-7">
					<span class="middle"><font color="red">*</font></span>
				</span>
			</div>
		</div>
		<div class="space-4"></div>
		
		<div class="clearfix form-actions">
			<div class="col-md-offset-3 col-md-9">
				<form:button class="btn btn-info"><i class="icon-ok bigger-110"></i>${op}</form:button>
				&nbsp; &nbsp; &nbsp;
				<button class="btn" type="button" onclick="javascript:history.go(-1);"><i class="icon-off bigger-110"></i>关闭</button>
			</div>
		</div>
    </form:form>
		
	<%@include file="/WEB-INF/pages/common/basic-scripts.jspf" %>   
	<script>
		function validForm() {
	    	var name = $("#name").val();
	    	if (isEmpty(name)) {
	    		defaultAlert("节点名不能为空");
	    		return false;
	    	}
	    	var orderNum = $("#orderNum").val();
	    	if (isEmpty(orderNum)) {
	    		defaultAlert("排序号不能为空");
	    		return false;
	    	}
	    	var parentOrderNum = $("#parentOrderNum").val();
	    	if (!checkInt(orderNum) || parseInt(orderNum) <= parentOrderNum) {
	    		defaultAlert("排序号必须为正整数，并且大于父节点的排序号");
	    		return false;
	    	}	    
	    	loading();
	    	return true;
	    }
	</script>
</body>
</html>